package au.com.betaversion.aws;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;

public class AmazonS3 {
	
	private static final String BUCKET_NAME = "planespotter";
	
	private AmazonS3Client amazonS3Client = null;
	private ClasspathPropertiesFileCredentialsProvider classpathPropertiesFileCredentialsProvider = null;
	
	@Before
	public void before() {
		this.classpathPropertiesFileCredentialsProvider = new ClasspathPropertiesFileCredentialsProvider();
		this.amazonS3Client = new AmazonS3Client(this.classpathPropertiesFileCredentialsProvider);
	}
	
	@After
	public void after() {
		this.amazonS3Client.shutdown();
		this.amazonS3Client = null;
	}
	
	@Test
	public void s3ClientEstablished() {
		assertNotNull(this.amazonS3Client);
	}
	
	@Test
	public void s3ListBuckets() {
		assertTrue(this.amazonS3Client.listBuckets().size() > 0);
	}
	
	@Test
	public void s3GetObject() {
		GetObjectRequest getObjectRequest = new GetObjectRequest(BUCKET_NAME, "72945cc7-1a99-49be-8147-e3010ef1a975.JPG");
		S3Object s3Object = this.amazonS3Client.getObject(getObjectRequest);
		assertNotNull(s3Object);
	}

}